package com.ys.controller.web.business;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import com.bo.vo.W;
import com.ys.config.MenuId;
import com.ys.config.MyConfig;
import com.ys.entity.business.TbBaseInfo;
import com.ys.service.sys.CommonApiService;

@Controller
@RequestMapping("/web/business/tbBaseInfo")
public class WebTbBaseInfoController {

	@Autowired
	private CommonApiService<TbBaseInfo> commonApiService;

	Long menuId = MenuId.TB_BaseInfo;
	/*
	 * 新增
	 */
	@GetMapping("/toAdd")
	public String toAdd(Model model) throws Exception{
		Map<String,Object> tbBaseInfo = new HashMap<>();
		tbBaseInfo.put("status",1);

		TbBaseInfo entity = new TbBaseInfo()
				.setCreateTime(new Date());
		entity.setBid(commonApiService.getCommonNextUkey(MenuId.TB_BaseInfo, "bid"));
		String aa = commonApiService.toAdd(model, entity, MenuId.TB_BaseInfo, tbBaseInfo, null);
        
        if ("test".equals(MyConfig.getActive()) || "pro".equals(MyConfig.getActive())) {
			return "business/tbBaseInfo/tbBaseInfoAdd";
		} else {
			return aa;
		}
	}

	/*
	 * 编辑
	 */
	@GetMapping("/toEdit")
	public String toEdit(Model model, Long id) throws Exception{
		
		if (id == null) {
			return W.error(model, "ID不能为空");
		}

		if (new TbBaseInfo().setId(id).count() == 0){
			return W.error(model, "该信息不存在!");
		}
		
		String aa = commonApiService.toEdit(model, id, new TbBaseInfo(), MenuId.TB_BaseInfo, null, null);
        
        if ("test".equals(MyConfig.getActive()) || "pro".equals(MyConfig.getActive())) {
    		return "business/tbBaseInfo/tbBaseInfoEdit";
		} else {
			return aa;
		}

	}

}
